import { UniversalList } from "./Genericmethods";
// 列表http://10.199.98.2:8086/3DInterface_D/Business/EmergManage/yjgl_zsgc
export function getLists(Listparameters) {
  const getAllParams = {
    SQL: `SELECT * FROM IMP_EmergManage.${Listparameters}`,
    TIP: "select",
  };

  return UniversalList(getAllParams)
    .then((res) => {
      // console.log(res.data);
      return res.data.data;
    })
    .catch((error) => {
      console.log(error);
      throw error;
    });
}
// http://10.118.16.65:8086/api/v2/IMP_DBInterface/EmergManage/yjgl_zsgc?SQL=INSERT INTO IMP."EmergMatList" ("InstallLocal","Name","Specs","Unit","Num") VALUES ('1','2','3','4','6') &TIP=insert
// 添加
export function insertData(Listparameters, fieldlist, data) {
  const params = {
    SQL: `insert into IMP_EmergManage.${Listparameters}(${fieldlist}) values(${data})`,
    TIP: 'insert',
  };

  return UniversalList(params)
    .then((res) => {
      // console.log(res.data);
      return {
        data: res.data,
        getAllParams: params
      };
    })
    .catch((error) => {
      console.log(error);
      throw error;
    });
}
// http://10.118.16.65:8086/api/v2/IMP_DBInterface/EmergManage/yjgl_zsgc?SQL=DELETE from  "EmergMatList" WHERE "InstallLocal" = '2' and "Name" = '3' and "Specs" = '4' and "Unit" = '5' and "Num" = '6'&TIP=delete
// 删除
export function deletelist(Listparameters, data) {
  const params = {
    SQL: `DELETE from IMP_EmergManage.${Listparameters} WHERE ${data}`,
    TIP: 'delete',
  };
  return UniversalList(params)
    .then((res) => {
      // console.log(res.data);
      return {
        data: res.data,
        getAllParams: params
      };
    })
    .catch((error) => {
      console.log(error);
      throw error;
    });
}
// 删除全部DELETE FROM IMP_EmergManage."OperationLogList"
export function ALLdeletelist(Listparameters) {
  const params = {
    SQL: `DELETE FROM IMP_EmergManage.${Listparameters}`,
    TIP: 'delete',
  };
  return UniversalList(params)
    .then((res) => {
      // console.log(res.data);
      return {
        data: res.data,
        getAllParams: params
      };
    })
    .catch((error) => {
      console.log(error);
      throw error;
    });
}
// UPDATE IMP_EmergManage."EmergMatList" set "InstallLocal" = '2',"Name" = '3',"Specs" = '4',"Unit" = '5',"Num" = '6' where "InstallLocal" = '1' and "Name" = '2' and "Specs" = '3' and "Unit" = '4' and "Num" = '5'
// 修改  data为修改后数组，Originalarray为原始数组
export function ModifierList(Listparameters, data, Originalarray) {
  const params = {
    SQL: `UPDATE IMP_EmergManage.${Listparameters} set ${data} where ${Originalarray}`,
    TIP: 'update',
  };
  return UniversalList(params)
    .then((res) => {
      return {
        data: res.data,
        getAllParams: params
      };
    })
    .catch((error) => {
      console.log(error);
      throw error;
    });
}